import FyComponent from '@/components/common/countdown'
import { View } from '@tarojs/components'
import classNames from 'classnames'
import { calcSurplusTime } from '@/utils/utils'

interface IProps {
  seconds: number
  onTimeUp?: any
  className?:string
}

export default class UnpaidCountdown extends FyComponent<IProps, {}> {
  constructor(props) {
    super(props)
    const { minutes, seconds } = calcSurplusTime()
    this.state = {
      minutes,
      seconds
    }
  }

  //  倒计时回调
  onCallBack () {
    const { minutes, seconds } = calcSurplusTime(this.seconds)

    this.setState({
      minutes,
      seconds
    })
  }

  //  时间到
  onTimeUp() {
    this.props.onTimeUp && this.props.onTimeUp()
  }

  render() {
    const { className } = this.props
    const { minutes, seconds } = this.state
    return (<View className={classNames('order-count-down', className)}>
      {this.formatNum(minutes)}:{this.formatNum(seconds)}
    </View>)
  }
}
